<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
    <link rel="stylesheet" href="../javascripts/lib/jqm/jquery.mobile-1.4.3.min.css"/>
    <link rel="stylesheet" href="../stylesheets/main.css"/>
    <script src="../javascripts/lib/jq/jquery-2.1.1.min.js"></script>
    <script src="../javascripts/lib/jqm/jquery.mobile-1.4.3.min.js"></script>
    <script type="text/javascript" charset="utf-8">
    // $(document).ready(function(){
    // $("#listview").listview({splitIcon: "star" });
    // });
    function wcback(){
        WeixinJSBridge.call('closeWindow');//微信内置浏览器关闭当前页面
    }
    </script>

    <title><%=title%></title>
  </head>
  <body>
    <div class="a" data-role="page" id="glpage">

      <div data-role="header" id="header">
          <a class="ui-btn-left ui-btn ui-btn-inline ui-mini ui-corner-all ui-btn-icon-left ui-icon-delete" onclick="wcback()" href="#">关闭</a>
          <h1>购买</h1>
          <a class="ui-btn ui-corner-all ui-btn-inline ui-mini footer-button-right ui-btn-icon-right ui-icon-carat-r" data-transition="slide" href="/wcpay/orderlist?openid=<%=openid%>">购买记录</a>
      </div>
      <div data-role="content" data-theme="c" >
          <script type="text/javascript">
              function pay(id){
                  id = $.trim(id);
                  //alert('sss'+id+'sss');
                  var args = {
                      goodid:id,
                      openid:'<%=openid%>',
                      appid:'<%=appid%>'
                  }
                  //alert('goodid'+id+'--openid'+args.openid+'--appid'+args.appid);return;
                  $.post('/wcpay/pay', args, function(result){
                  //$.get("/wcpay/pay?goodid="+id, function(result){
                      //$("#sss").html(result);
                      //alert(result.tradeno);
                      //alert(result.payinfo);
                    WeixinJSBridge.invoke('getBrandWCPayRequest',result.payinfo,function(res){
                         //alert(res.err_msg);
                         if(res.err_msg=="get_brand_wcpay_request:ok"){
                            /*$.get("/wcpay/pay_end?tradeno="+result.tradeno, function(result){
                            });*/
                             window.location.href="/wcpay/pay_end?tradeno="+result.tradeno;
                         }
                    });
                  });
              }
          </script>
          <ul id="listview" data-role="listview" data-inset="true">
          <%goods.forEach(function(good){%>
            <li>
              <div class="gridrow">
                <img src="../images/logo.png" alt="" height="115px"/>
                <label style="overflow:hidden;text-overflow:ellipsis;"><%=good.name%></label>
                <label>价格：￥<%=good.price%></label>
                <a data-role="button" class="btnBack" onclick="pay('+<%=good._id%>+');">直接购买</a>
                  <!--<a href="/wcpay/pay?goodid=<=good._id>" data-role="button" class="btnBack">购买</a>-->
              </div>
            </li>
          <%});%>
          </ul>
          <a href="/wcpay/payoff/exchange?openid=<%=openid %>" data-transition="slide" data-role="button" style="margin-top: 20px;">兑换点数（当前<span style="color: red;"><%=payoff_count%></span>点）</a>
      </div>
       <!-- <a href="/wcpay/pay_end?tradeno=<=tradeno>" id="wcpayend"></a>-->
        <!--<input type="button" name="" id="wcpay" value="微信支付aaa" onclick="ttt();">-->
    </div>

  </body>
</html>